package com.bzyd.jpa.controller;

import com.bzyd.jpa.dao.JpaUserDao;
import com.bzyd.jpa.entity.JpaUser;
import com.bzyd.jpa.specification.JpaUserSpecification;
import com.bzyd.jpa.vo.JpaUserQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户接口
 */
@RestController
@RequestMapping("user")
public class JpaUserController {

    @Autowired
    private JpaUserDao jpaUserDao;

    @RequestMapping("/queryUser")
    public Page<JpaUser> queryUser(JpaUserQueryVO param) {
        //省略service
        Pageable pageable = PageRequest.of(param.getPageIndex() - 1, param.getPageSize());
        JpaUserSpecification specification = new JpaUserSpecification(param);
        Page<JpaUser> page = jpaUserDao.findAll(specification, pageable);
        return page;
    }
}
